<?php
class PagesController extends AppController {
	var $name = 'Pages';
	var $helpers = array();
	var $components = array('Init');
	var $uses = array('Picture','Product','Hitcounter');

	function beforeFilter() {
		$this->Init->startup($this);
		$this->Init->init();
		$this->Init->getKeyword();
		$_session = $this -> Session -> read();
		$row = $this->Hitcounter->get(session_id());
		if ($row == 0) {
			$data = array(
				"session_id" => session_id(),
				"ref_url" => env("REQUEST_URI"),
				"ip_address" => env("REMOTE_ADDR"),
				"activity" => date("Y-m-d H:i:s")
			);
			$this->Hitcounter->save($data);
		}
	}

	function index() {
		$this->set('activeNav', 'Home');

		if (!$this->Session->read("lang")) {
			$lang = "eng";
		} else {
			$lang = $this->Session->read("lang");
		}

		
		/* banner */
		$slides = $this->Picture->find('all', array(
			'conditions' => array(
				'Picture.status' => 1,
				'Picture.kind' => 1,
			),
			'limit'	=> 11,
			'fields' => array('Picture.name_'.$lang, 'Picture.description_'.$lang, 'Picture.image_link'),
			'order'	=> 'Picture.sort asc'
		));

		$this->set('lang', $lang);
		$this->set('advertises', $slides);

		/* sale products */

		$saleProducts = $this->Product->find('all', array(
			'conditions' =>  array('Product.status' => 1,'Product.discount_price >' => 0),
			'order'		 =>  'Product.updated_date desc',
			'limit'		 =>  8
		));
		$this->set('saleProducts', $saleProducts);

		$hotProducts = $this->Product->find('all', array(
			'conditions' =>  array('Product.status' => 1,'Product.isHot >' => 0),
			'order'		 =>  'Product.updated_date desc',
			'limit'		 =>  8
		));
		$this->set('hotProducts', $hotProducts);
	}
}
?>
